package MyStack;

import java.util.Arrays;
import java.util.SplittableRandom;

public class MyStack {
    private int[] elem;
    private int Usesize;//有效个数
    private static int Fistszie=10;//初始空间大小
    public MyStack() {
        elem=new int[Fistszie];
    }
    public void push(int e){
        if(ifFull()){//判断是否要扩容
            grow();
        }
        elem[Usesize]=e;
        Usesize++;
    }
    private void grow(){
        elem= Arrays.copyOf(elem,elem.length);
    }
    private boolean ifFull(){
        if(Usesize==elem.length){
        return true;}
        else return false;

    }
    public int pop(){
        if(empty()){
            throw new Ofoutexpention("没有数据");
        }
        Usesize--;
        return elem[Usesize];

    }
    public int peek(){
        if (Usesize==0){
           throw new Ofoutexpention("没有数据");
        }
        return elem[Usesize-1];
    }
    public boolean empty(){
        if(Usesize==0){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        MyStack myStack=new MyStack();
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        System.out.println(myStack.empty());
        System.out.println(myStack.peek());

    }


}
